<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

use Doctrine\Common\Util\Debug;

class fixtures extends Controller {

	function index(){
		echo '<pre>';

		$kamus_nama_1 = array(
			'Joko',
			'Susilo',
			'Bambang',
			'Ahmad',
			'Gayus',
			'Sarah',
			'Prita',
			'Muhammad',
			'Sinta',
			'Adrian',
			'Nasaruddin',
			'Budi',
		);

		$kamus_nama_2 = array(
			'Subianto',
			'Mulyasari',
			'Supomo',
			'Widyowoko',
			'Ilyas',
			'Nugraha',
			'Tambunaan',
			'Yudhoyono',
			'Supomo',
			'Hidayat',
			'Amalia',
		);

		$kamus_nama_3 = array(
			'Karyono',
			'Hadi',
			'Simon',
			'Yoyok',
			'Yusuf',
		);

		$kamus_nama_4 = array(
			'Mashub',
			'Kodradi',
			'Salim',
			'Santoso',
			'Samin',
		);

		$kamus_perusahaan_1 = array(
			'CV',
			'PT',
			'Koperasi',
			'LSM',
			'SD',
			'SMP',
			'SMA',
			'Universitas',
		);

		$kamus_perusahaan_2 = array(
			'Anugrah',
			'Selamat',
			'Patriot',
			'Semangat',
			'Graha',
		);

		$kamus_perusahaan_3 = array(
			'Sejahtera',
			'Bela Negara',
			'Ilmu',
			'Nasionalis',
			'Nusantara',
		);

		$kamus_kondisi = array(
			'ok',
			'nok',
		);

		$kamus_remarks_nok = array(
			'perlu diganti',
			'masalah driver',
			'kena virus',
			'kepanasan',
			'ram-nya kurang',
			'belum tahu masalahnya',
		);

		$kamus_remarks_ok = array(
			'sempurna',
			'tidak ada masalah',
			'sudah stabil',
			'kembali seperti semula',
		);

		//administrator
		$admin = new models\Akun('admin','admin','admin@scihs.org','Administrator');
		$this->doctrine->em->persist($admin);

		//paket_langganan
		$pl_arr = array();
		$pl_arr[] = new models\Paket_langganan('Home',3,2,35000);
		$pl_arr[] = new models\Paket_langganan('SoHo',9,2,90000);
		$pl_arr[] = new models\Paket_langganan('School',20,3,120000);
		$pl_arr[] = new models\Paket_langganan('Corporate',25,3,175000);
		foreach($pl_arr as $row){
			$this->doctrine->em->persist($row);
		}

		//agen
		$agen_arr = array();
		for($i=1;$i<=15;++$i){
			$username = sprintf('A%04d',$i);
			$pass = $username;
			$email = $username.'@yahoo.com';
			$nama = $kamus_nama_3[rand(0,count($kamus_nama_3)-1)]
				.' '.$kamus_nama_4[rand(0,count($kamus_nama_4)-1)];

			$a = new models\Agen($username,$pass,$email,$nama);
			$a->set_alamat('Jl. Anonim no '.rand(0,99));
			$a->set_kodepos(sprintf('672%02d',rand(0,99)));
			$a->set_kota('Surabaya');
			$a->set_propinsi('Jawa Timur');
			$a->set_telepon(sprintf('031-523%03d',rand(0,999)));
			$agen_arr[] = $a;
			$this->doctrine->em->persist($a);
		}

		//customer/perusahaan
		$cus_arr = array();
		for($i=1;$i<=30;++$i){

			$username = sprintf('C%04d',$i);
			$pass = $username;
			$email = $username.'@yahoo.com';

			$tipe = rand(0,1);
			if($tipe == 0){
				$nama = $kamus_nama_1[rand(0,count($kamus_nama_1)-1)]
					.' '.$kamus_nama_2[rand(0,count($kamus_nama_2)-1)];
				$c = new models\Customer($username,$pass,$email,$nama);
				$pl = $pl_arr[0];
			} else {
				$nama = $kamus_perusahaan_1[rand(0,count($kamus_perusahaan_1)-1)]
					.' '.$kamus_perusahaan_2[rand(0,count($kamus_perusahaan_2)-1)]
					.' '.$kamus_perusahaan_3[rand(0,count($kamus_perusahaan_3)-1)];
				$c = new models\Perusahaan($username,$pass,$email,$nama);
				$pl = $pl_arr[rand(1,3)];
				$nama_pj = $kamus_nama_1[rand(0,count($kamus_nama_1)-1)]
					.' '.$kamus_nama_2[rand(0,count($kamus_nama_2)-1)];
				$c->set_penanggung_jawab($nama_pj);
				$c->set_jabatan('Direktur');
				$c->set_jenis_usaha('Pembalakan Liar');
				$c->set_website('www.google.com');
			}
			$c->set_paket_langganan($pl);
			$c->set_alamat('Jl. Anonim no '.rand(0,99));
			$c->set_kodepos(sprintf('672%02d',rand(0,99)));
			$c->set_kota('Surabaya');
			$c->set_propinsi('Jawa Timur');
			$c->set_telepon(sprintf('031-523%03d',rand(0,999)));
			$c->set_jenis_identitas('ktp');
			$c->set_no_identitas(sprintf('510710%03d',rand(0,999)));
			$c->set_npwp(sprintf('510710%03d',rand(0,999)));
			$c->set_telepon_seluler(sprintf('08564850%04d',rand(0,9999)));
			$c->set_fax(sprintf('031-555%03d',rand(0,999)));
			$c->set_agen($agen_arr[rand(0,count($agen_arr)-1)]);
			$cus_arr[] = $c;
			$this->doctrine->em->persist($c);
		}

		//Teknisi
		$tek_arr = array();
		for($i=1;$i<=15;++$i){
			$username = sprintf('T%04d',$i);
			$pass = $username;
			$email = $username.'@yahoo.com';
			$nama = $kamus_nama_3[rand(0,count($kamus_nama_3)-1)]
				.' '.$kamus_nama_4[rand(0,count($kamus_nama_4)-1)];

			$t = new models\Teknisi($username,$pass,$email,$nama);
			$t->set_keahlian('Reparasi Elektronik');
			$t->set_alamat('Jl. Anonim no '.rand(0,99));
			$t->set_kodepos(sprintf('672%02d',rand(0,99)));
			$t->set_kota('Surabaya');
			$t->set_propinsi('Jawa Timur');
			$t->set_telepon(sprintf('031-523%03d',rand(0,999)));
			$tek_arr[] = $t;
			$this->doctrine->em->persist($t);
		}

		//Speedy
		$spe_arr = array();
		for($i=1;$i<=25;++$i){
			$nama = $kamus_nama_1[rand(0,count($kamus_nama_1)-1)]
				.' '.$kamus_nama_2[rand(0,count($kamus_nama_2)-1)];
			$agen = $agen_arr[rand(0,count($agen_arr)-1)];
			$s = new models\Speedy($agen);
			$s->set_nama($nama);
			$s->set_alamat('Jl. Anonim no '.rand(0,99));
			$s->set_telepon(sprintf('031-523%03d',rand(0,999)));
			$s->set_paket_speedy('personal');
			$spe_arr[] = $s;
			$this->doctrine->em->persist($s);
		}

		//Kunjungan
		$kun_arr = array();
		for($i=1;$i<=60;++$i){
			$customer = $cus_arr[rand(0,count($cus_arr)-1)];
			$teknisi = $tek_arr[rand(0,count($tek_arr)-1)];
			$tanggal = new Datetime('2011-02-'.rand(1,28));
			$k = new models\Kunjungan($customer,$teknisi,$tanggal);
			$kun_arr[] = $k;
			$this->doctrine->em->persist($k);
		}

		//Jenis_device
		$jd_arr = array();

		$jd_arr[] = $jd_pc = new models\Jenis_device('PC Desktop / Laptop');
		$jd_pc->add_objek_pengecekan(new models\Objek_pengecekan('Operating System'));
		$jd_pc->add_objek_pengecekan(new models\Objek_pengecekan('Office'));
		$jd_pc->add_objek_pengecekan(new models\Objek_pengecekan('Anti-Virus'));
		$jd_pc->add_objek_pengecekan(new models\Objek_pengecekan('Hardware'));
		$jd_pc->add_objek_pengecekan(new models\Objek_pengecekan('Performance'));
		$jd_pc->add_objek_pengecekan(new models\Objek_pengecekan('Networking'));
		$jd_pc->add_objek_pengecekan(new models\Objek_pengecekan('Monitor'));
		$jd_pc->add_objek_pengecekan(new models\Objek_pengecekan('Printer'));
		$jd_pc->add_objek_pengecekan(new models\Objek_pengecekan('Scanner'));
		$jd_pc->add_objek_pengecekan(new models\Objek_pengecekan('Stavolt'));
		$jd_pc->add_objek_pengecekan(new models\Objek_pengecekan('UPS'));

		$jd_arr[] = $jd_ro = new models\Jenis_device('Router');
		$jd_ro->add_objek_pengecekan(new models\Objek_pengecekan('Software'));
		$jd_ro->add_objek_pengecekan(new models\Objek_pengecekan('Hardware'));

		$jd_arr[] = $jd_sw = new models\Jenis_device('Switch / Catalyst');
		$jd_sw->add_objek_pengecekan(new models\Objek_pengecekan('Software'));
		$jd_sw->add_objek_pengecekan(new models\Objek_pengecekan('Hardware'));

		$jd_arr[] = $jd_hu = new models\Jenis_device('Hub / Bridge');
		$jd_hu->add_objek_pengecekan(new models\Objek_pengecekan('Cable Terminating'));
		$jd_hu->add_objek_pengecekan(new models\Objek_pengecekan('Cable Installation'));

		foreach($jd_arr as $jd){
			$this->doctrine->em->persist($jd);
			foreach($jd->get_objek_pengecekan() as $op){
				$this->doctrine->em->persist($op);
			}
		}

		//Checklist & Detail_checklist
		$cl_arr = array();
		$dl_arr = array();
		for($i=1;$i<=100;++$i){

			$kunjungan = $kun_arr[rand(0,count($kun_arr)-1)];
			$jenis_device = $jd_arr[rand(0,count($jd_arr)-1)];
			$cl = new models\Checklist('tes',$kunjungan,$jenis_device);

			foreach($jenis_device->get_objek_pengecekan() as $op){

				$kondisi = $kamus_kondisi[rand(0,1)];
				if($kondisi == 'ok') $remarks = $kamus_remarks_ok[rand(0,count($kamus_remarks_ok)-1)];
				else $remarks = $kamus_remarks_nok[rand(0,count($kamus_remarks_nok)-1)];

				$dl = new models\Detail_checklist($cl,$op,$kondisi,$remarks);
				$dl_arr[] = $dl;
				$this->doctrine->em->persist($dl);
			}
			$cl_arr[] = $cl;
			$this->doctrine->em->persist($cl);
		}

		//Debug::dump($pl_arr);
		//Debug::dump($agen_arr);
		//Debug::dump($cus_arr);
		//Debug::dump($tek_arr);
		//Debug::dump($spe_arr);
		//Debug::dump($kun_arr[0]->get_tanggal());
		//Debug::dump($jd_arr);
		//Debug::dump($cl_arr[0]->get_detail_checklist());
		//Debug::dump($dl_arr);

		echo '</pre>';
		$this->doctrine->em->flush();
	}
}
